package inf.coach.mobile;

import java.util.List;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.IBinder;
import android.telephony.TelephonyManager;
import android.widget.Toast;



public class ConnectionReceiver {

	public static boolean isInternetConnected(Context context) {   
		   
		   ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		
		   NetworkInfo info=cm.getActiveNetworkInfo();   
		   //NetworkInfo minfo=cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
		   //NetworkInfo winfo=cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
		   if(info!=null && info.isConnectedOrConnecting() && !info.isConnected())
		   {
			   Toast.makeText( context, "Active Network Type : " + 
					   info.getTypeName()+" is connecting !", Toast.LENGTH_SHORT ).show();
			   System.out.println("connected");
		   }
		   
		   if(info!=null && info.isConnected())
		   {
			   System.out.println("connected..");
			   return true;
			  
		   }else{
			   return false;   
			  }
		   
		}  
	
	public boolean isGpsEnabled(Context context)
	{
	LocationManager locationManager =
	((LocationManager)context.getSystemService(Context.LOCATION_SERVICE));
	List<String> accessibleProviders = locationManager.getProviders(true);
	return accessibleProviders != null && accessibleProviders.size() > 0;
	}

	
	public boolean isWifiEnabled(Context context)
	{
	ConnectivityManager mgrConn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 
	TelephonyManager mgrTel = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); 
	return ((mgrConn.getActiveNetworkInfo()!=null && mgrConn.getActiveNetworkInfo().getState()==NetworkInfo.State.CONNECTED) 
	|| mgrTel.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS) ;
	}
	
	public static boolean isNetworkConnected(Context context){  
	  ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);  
	  NetworkInfo network = cm.getActiveNetworkInfo();  
	  if(network != null){  
	  return network.isAvailable();  
	  }  
	  return false;  
	}   

}
